﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.franchise.display {
    import flash.display.*;
    import org.aswing.*;
    import org.aswing.event.*;
    import Modules.franchise.data.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class FranchiseTabScrollingList extends JPanel {

        public static const NUM_ITEMS:int = 6;
        private static const TAB_WIDTH:int = 103;

        protected var m_cellFactory:GridListCellFactory;
        protected var m_dataList:GridList;
        protected var m_tabData:VectorListModel;
        protected var m_data:Array;
        protected var m_scrollPane:JScrollPane;
        protected var prevButton:JButton;
        protected var nextButton:JButton;
        protected var m_columns:int;
        protected var m_rows:int;
        protected var m_model:VectorListModel;
        protected var m_curCount:int = 0;
        protected var m_curIndex:int = 0;
        protected var m_tabs:Array;

        public function FranchiseTabScrollingList(_arg1:Array, _arg2:Class, _arg3:int, _arg4:int=0, _arg5:int=1, _arg6:int=6){
            super(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 0, SoftBoxLayout.CENTER));
            this.m_cellFactory = new (_arg2)();
            this.m_columns = _arg4;
            this.m_rows = _arg5;
            this.m_data = _arg1;
            this.makeTabs(_arg6);
            this.makeButtons();
            this.makeSize();
            this.append(this.prevButton);
            this.append(this.m_scrollPane);
            this.append(this.nextButton);
            ASwingHelper.prepare(this);
            if (FranchiseMenu.selectedFranchise){
                this.setSelected(FranchiseMenu.selectedFranchise.franchiseType);
            };
        }
        protected function makeTabs(_arg1:int=6):void{
            this.m_model = new VectorListModel();
            var _local2:int = Math.min(_arg1, this.m_data.length);
            var _local3:int;
            while (_local3 < _local2) {
                this.m_model.append(this.m_data[_local3]);
                this.m_curCount++;
                _local3++;
            };
            this.m_curIndex = (this.m_curCount - 1);
            var _local4:OwnedFranchiseData = new OwnedFranchiseData("bus_dummy", "", null, null, 0);
            this.m_tabData = new VectorListModel();
            this.m_tabData.appendAll(this.m_model.toArray());
            this.m_tabData.append(_local4);
            this.m_dataList = new GridList(this.m_tabData, this.m_cellFactory, this.m_columns, this.m_rows);
            this.m_tabs = this.m_dataList.getCells().toArray();
            this.m_scrollPane = new JScrollPane(this.m_dataList, JScrollPane.SCROLLBAR_NEVER, JScrollPane.SCROLLBAR_NEVER);
        }
        public function setSelected(_arg1:String):void{
            var _local2:FranchiseTab;
            for each (_local2 in this.m_tabs) {
                if (_local2.franchiseType == _arg1){
                    _local2.selectionStatus = true;
                } else {
                    _local2.selectionStatus = false;
                };
            };
        }
        protected function makeButtons():void{
            var _local4:DisplayObject;
            var _local5:DisplayObject;
            var _local1:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_prev_normal"])() as DisplayObject);
            var _local2:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_prev_down"])() as DisplayObject);
            var _local3:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_prev_over"])() as DisplayObject);
            _local4 = (new (FranchiseMenuUI.m_assetDict["fr_next_normal"])() as DisplayObject);
            _local5 = (new (FranchiseMenuUI.m_assetDict["fr_next_down"])() as DisplayObject);
            var _local6:DisplayObject = (new (FranchiseMenuUI.m_assetDict["fr_next_over"])() as DisplayObject);
            this.prevButton = new JButton();
            this.prevButton.wrapSimpleButton(new SimpleButton(_local1, _local3, _local2, _local1));
            this.prevButton.setEnabled(false);
            this.nextButton = new JButton();
            this.nextButton.wrapSimpleButton(new SimpleButton(_local4, _local6, _local5, _local4));
            if (this.m_model.getSize() < NUM_ITEMS){
                this.nextButton.setEnabled(false);
            } else {
                this.nextButton.setEnabled(true);
            };
            this.prevButton.addActionListener(this.moveLeft, 0, true);
            this.nextButton.addActionListener(this.moveRight, 0, true);
        }
        protected function moveLeft(_arg1:AWEvent):void{
            this.m_curIndex = Math.max((this.m_curIndex - 1), 0);
            if (this.m_curIndex < NUM_ITEMS){
                this.prevButton.setEnabled(false);
                this.m_curIndex = (NUM_ITEMS - 1);
            };
            this.nextButton.setEnabled(true);
            this.m_dataList.scrollHorizontal(-(TAB_WIDTH));
        }
        protected function moveRight(_arg1:AWEvent):void{
            var _local4:int;
            var _local2:int = this.m_curCount;
            var _local3:int = Math.min(this.m_tabData.getSize(), (this.m_curCount + 1));
            _local3 = Math.min(_local3, this.m_data.length);
            if ((_local3 - _local2) > 0){
                if (this.m_model.getSize() < (this.m_curCount + 1)){
                    _local4 = _local2;
                    while (_local4 < _local3) {
                        this.m_model.append(this.m_data[_local4]);
                        this.m_tabData.insertElementAt(this.m_data[_local4], (this.m_tabData.getSize() - 1));
                        this.m_curCount++;
                        _local4++;
                    };
                    this.m_tabs = this.m_dataList.getCells().toArray();
                };
            };
            this.m_curIndex = Math.min((this.m_curIndex + 1), (this.m_tabData.getSize() - 1));
            if (this.m_curIndex >= this.m_data.length){
                this.nextButton.setEnabled(false);
            };
            this.prevButton.setEnabled(true);
            this.m_dataList.scrollHorizontal(TAB_WIDTH);
        }
        public function scrollToItemIndex(_arg1:int):void{
            if ((((_arg1 < 0)) || ((_arg1 >= this.m_tabData.getSize())))){
                return;
            };
            while (_arg1 < this.m_curIndex) {
                this.moveLeft(null);
            };
            while (_arg1 >= (this.m_curIndex + 1)) {
                this.moveRight(null);
            };
        }
        protected function makeSize():void{
            this.setPreferredHeight(120);
            this.m_scrollPane.setPreferredWidth((TAB_WIDTH * NUM_ITEMS));
        }
        public function get dataList():GridList{
            return (this.m_dataList);
        }

    }
}//package Modules.franchise.display 
